home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5442 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: mail2news.demon.co.uk!hpl3sn03.cern.ch
  2. From: Dan Pop <danpop@mail.cern.ch>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: simple code, argc, argv, strcmp()
  5. Date: Sat, 10 Feb 1996 04:09:32 +0100
  6. Organization: CERN European Lab for Particle Physics
  7. Message-ID: <9602100309.AA15971@dxmint.cern.ch>
  8. References: <11f7cc$17261a.3b3@daprez> <harmon.823197381@pegasus.montclair.edu>
  9. X-NNTP-Posting-Host: hpl3sn03.cern.ch
  10. X-Newsreader: NN version 6.5.0 #7 (NOV)
  11. X-Mail2News-Path: dxmint.cern.ch!hpl3sn03.cern.ch
  12.  
  13. harmon@pegasus.montclair.edu (Derek Harmon) writes:
  14.  
  15. >otisg@panther.middlebury.edu (Otis Gospodnetic) writes:
  16. >>  if (!strcmp(argv[1],"-d") || !strcmp(argv[1],"-e")) {
  17. >>    Usage();
  18. >>  }
  19. >
  20. >   This is where your troubles lie.  Let's think for a second, if argv[1]
  21. >is "-d", then the first clause is false.  BUT, if argv[1] is "-d" then it
  22. >cannot also be "-e", so the second clause is true, and Usage() is called.
  23. >On the other hand, if argv[1] is "-e", then the second clause is false.
  24. >Unfortunately, argv[1] is then surely not "-d", and the first clause is true.
  25. >
  26. >   Therefore, I would suggest that you only call Usage() when argv[1] is
  27. >not "-d" AND not "-e":
  28. >
  29. >:   if (!strcmp(argv[1],"-d") && !strcmp(argv[1],"-e")) {
  30.  
  31. Yet another guy who got it wrong :-)  This will evaluate to 1 only when
  32. argv[1] is "-d" AND "-e", i.e. NEVER.
  33.  
  34. !strcmp() is EVIL and this thread demonstrated it a zillion times.
  35. Don't use it if you want to preserve your sanity :-)
  36.  
  37. Dan
  38. -- 
  39. Dan Pop
  40. CERN, CN Division
  41. Email: danpop@mail.cern.ch 
  42. Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
  43.